#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "../include/phone.h"
#include "../include/func.h"

int login_menu(void)
{
    int i=3;
    char passwd[32] = {0};
    printf("=======================================\n");
	printf("| 								      |\n");
	printf("|       welcome to my project 		  |\n");
	printf("| 								      |\n");
	printf("| Tips: init password(yikoupeng)      |\n");
	printf("=======================================\n");

    while(i > 0)
    {
        printf("please input your password:\n");
        scanf("%s", passwd);
        if(strcmp(password, passwd) == 0)
        {
            return 0;
        }
        else
        {
            i--;
            printf("password error!,The remaining number of times is:%d\n",i);
        }
    }
    if(i == 0)
    {
        printf("over!\n");
        return -1;
    }
    return 0;
}

static int manage_menu()
{
    /*1.添加
     *2.删除
     *3.查找
     *4.显示所有记录
     *0.退出
     */
    int select;
    do{
        printf("************************************************\n");
		printf("|      1. create					 		   |\n");
		printf("|      2. delete					 		   |\n");
		printf("|      3. search					 		   |\n");
		printf("|      4. display all				 		   |\n");
		printf("|      0. quit					 		 	   |\n");
		printf("************************************************\n");
        printf("input your choice:");
        scanf("%d", &select);
        if(select < 0 || select > 4)
        {
            fflush(stdin);          //清空输入缓冲区
            printf("please try again\n");
            getchar();
            continue;
        }
        fflush(stdin);          //清空输入缓冲区，防止被下一次输入函数读取不正确的字符
        return select;
    }while(1);
}

int management(PHONE *head)
{
    int select;
    int flag = 0;

    do{
        
        system("clear");
        /*读取用户操作的选项*/
        select = manage_menu();
        switch (select)
        {
            case 1:
                create(head);
                //getchar();
				//getchar();				
				break;
            case 2:
                delete(head);
                //getchar();
				//getchar();				
				break;
            case 3:
                search(head);
                //getchar();
				//getchar();				
				break;
            case 4:
                display(head);				
				break;
            case 0:
                printf("Bye bye!\n");
                allfree(head);
                //getchar();
				//getchar();				
				flag = 1;
                    
            default:
                break;
        }
        if(flag == 1)
        {
            return 1;
        }    
    }while(1);
        
    return 0;
}







